/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.trick.admin.task;

import it.trick.admin.model.ChapterModel;
import it.trick.admin.model.PageModel;
import it.trick.admin.service.PageService;
import java.util.List;
import javafx.concurrent.Service;
import javafx.concurrent.Task;

/**
 *
 * @author takahara
 */
public class LoadPageListTask extends Service<List<PageModel>> {

    private ChapterModel chapterModel;

    public void setup(ChapterModel chapterModel) {
        this.chapterModel = chapterModel;
    }

    @Override
    protected Task createTask() {
        return new Task<List<PageModel>>() {
            @Override
            protected List<PageModel> call() throws Exception {

                List<PageModel> modelList = PageService.getList(chapterModel.getKeyValueString());
                for(PageModel pageModel: modelList) {
                    pageModel.setPrarentKeyString(chapterModel.getKeyValueString());
                }

                return modelList;
            }
        };
    }
}
